package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CompanyAddress;
import com.itheima.service.CompanyAddrService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/map")
public class CompanyAddrController {
    @Reference
    private CompanyAddrService companyAddrService;

    //回显所有门店地址
    @RequestMapping("/findMap")
    public Result findMap(){
        try {
            List<String> listAddr = companyAddrService.findMap();
            return new Result(true, "success",listAddr);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"false");
        }

    }

    //分页
    @RequestMapping("/pageQuery")
    public Result pageQuery(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult pageResult = companyAddrService.pageQuery(queryPageBean);
            return new Result(true, "success",pageResult);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"false");
        }
    }

    //新增门店地址
    @RequestMapping("/addCompanAddr")
    public Result addCompanAddr(@RequestBody CompanyAddress companyAddress){
        try {
            companyAddrService.addCompanyAddr(companyAddress);
            return new Result(true, "success");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"false");
        }
    }
    //删除门店地址
    @RequestMapping("/deleteCompantAddr")
    public Result deleteCompantAddr( Integer id){
        try {
            companyAddrService.deleteCompantAddr(id);
            return new Result(true, "success");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"false");
        }
    }
}
